﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.GateUI {
    import flash.display.*;
    import org.aswing.*;
    import com.greensock.*;
    import org.aswing.geom.*;
    import org.aswing.event.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class CrewScrollingList extends JPanel {

        public static const ROW_HEIGHT:int = 56;
        public static const ROW_WIDTH:int = 550;
        public static const USABLE_ROWS:int = 6;

        protected var m_dataList:GridList;
        protected var m_scrollPane:JScrollPane;
        protected var m_cellFactory:GridListCellFactory;
        protected var m_viewport:JViewport;
        protected var m_upBtn:JButton;
        protected var m_downBtn:JButton;
        protected var m_frame:JWindow;
        protected var m_rows:int;
        protected var m_columns:int;
        protected var m_data:Array;
        protected var m_tween:TweenLite;
        protected var m_activeSlots:int = 0;
        protected var curCount:int = 0;
        protected var m_model:VectorListModel;
        protected var m_topCrew:int = 0;

        public function CrewScrollingList(_arg1:Array){
            super(new FlowLayout(FlowLayout.LEFT, 0, 0));
            var _local2:IntDimension = new IntDimension(500, 56);
            this.m_cellFactory = new CrewCellFactory_2(CrewGateDialog_2.assetDict, _local2);
            this.m_columns = 1;
            this.m_rows = 6;
            this.m_data = _arg1;
            this.makeData();
            this.initSize();
            this.append(this.m_scrollPane);
            this.makeButtons();
            ASwingHelper.prepare(this);
        }
        protected function get TWEEN_TIME():Number{
            return (0.2);
        }
        protected function makeData():void{
            var _local1:int = (this.m_data.length - (Math.floor((this.m_data.length / USABLE_ROWS)) * USABLE_ROWS));
            var _local2:int = (USABLE_ROWS - _local1);
            if (_local2 >= USABLE_ROWS){
                _local2 = 0;
            };
            this.m_model = new VectorListModel();
            var _local3:int;
            while (_local3 < this.m_data.length) {
                this.m_model.append(this.m_data[_local3]);
                this.curCount++;
                _local3++;
            };
            _local3 = 0;
            while (_local3 < _local2) {
                this.m_model.append("empty");
                this.curCount++;
                _local3++;
            };
            this.m_dataList = new GridList(this.m_model, this.m_cellFactory, this.m_columns, 0);
            this.m_dataList.setColumns(1);
            this.m_dataList.setVGap(1);
            this.m_scrollPane = new JScrollPane(this.m_dataList, JScrollPane.SCROLLBAR_NEVER, JScrollPane.SCROLLBAR_NEVER);
        }
        public function updateCell(_arg1:int, _arg2):void{
            var _local3:CrewCell_2 = (this.m_dataList.getCellByIndex(_arg1) as CrewCell_2);
            this.scrollToCell(_arg1);
            _local3.setCellValue(_arg2);
        }
        protected function initSize():void{
            this.setPreferredHeight(360);
            this.m_dataList.setPreferredWidth(ROW_WIDTH);
            this.m_dataList.setMinimumWidth(ROW_WIDTH);
            this.m_dataList.setMaximumWidth(ROW_WIDTH);
            this.m_dataList.setPreferredHeight(345);
        }
        protected function makeButtons():void{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER, 30);
            ASwingHelper.setBackground(_local1, (new (CrewGateDialog_2.assetDict["police_scrollContainer"])() as DisplayObject));
            var _local2:DisplayObject = (new (CrewGateDialog_2.assetDict["conventionCenter_pagination_border"])() as DisplayObject);
            var _local3:DisplayObject = (new (CrewGateDialog_2.assetDict["conventionCenter_pagination_dot"])() as DisplayObject);
            var _local4:DisplayObject = (new (CrewGateDialog_2.assetDict["conventionCenter_pagination_top_up"])() as DisplayObject);
            var _local5:DisplayObject = (new (CrewGateDialog_2.assetDict["conventionCenter_pagination_top_over"])() as DisplayObject);
            var _local6:DisplayObject = (new (CrewGateDialog_2.assetDict["conventionCenter_pagination_bottom_up"])() as DisplayObject);
            var _local7:DisplayObject = (new (CrewGateDialog_2.assetDict["conventionCenter_pagination_bottom_over"])() as DisplayObject);
            this.m_upBtn = new JButton();
            this.m_upBtn.wrapSimpleButton(new SimpleButton(_local4, _local5, _local5, _local4));
            this.m_upBtn.setEnabled(false);
            ASwingHelper.setEasyBorder(this.m_upBtn, 110, 0, 0, 0);
            this.m_downBtn = new JButton();
            this.m_downBtn.wrapSimpleButton(new SimpleButton(_local6, _local7, _local7, _local6));
            if (this.m_data.length <= USABLE_ROWS){
                this.m_downBtn.setEnabled(false);
            };
            ASwingHelper.setEasyBorder(this.m_downBtn, 0, 0, 0);
            this.m_downBtn.addActionListener(this.moveDown, 0, true);
            this.m_upBtn.addActionListener(this.moveUp, 0, true);
            var _local8:AssetPane = new AssetPane((new (CrewGateDialog_2.assetDict["conventionCenter_pagination_dot"])() as DisplayObject));
            var _local9:JPanel = ASwingHelper.centerElement(_local8);
            _local1.setPreferredHeight(335);
            _local1.setPreferredWidth(50);
            _local1.appendAll(this.m_upBtn, _local9, this.m_downBtn);
            this.append(_local1);
        }
        protected function prepare():void{
            this.append(this.m_scrollPane);
            this.makeButtons();
            ASwingHelper.prepare(this);
        }
        protected function moveUp(_arg1:AWEvent=null):void{
            if (this.m_topCrew > 0){
                this.setupTween(this.m_topCrew, (this.m_topCrew - USABLE_ROWS));
                this.m_topCrew = (this.m_topCrew - USABLE_ROWS);
                this.m_downBtn.setEnabled(true);
                if (!(this.m_topCrew > 0)){
                    this.m_upBtn.setEnabled(false);
                };
            };
        }
        protected function moveDown(_arg1:AWEvent=null):void{
            if ((this.m_topCrew + USABLE_ROWS) < this.m_model.getSize()){
                this.setupTween(this.m_topCrew, (this.m_topCrew + USABLE_ROWS));
                this.m_topCrew = (this.m_topCrew + USABLE_ROWS);
                this.m_upBtn.setEnabled(true);
                if (!((this.m_topCrew + USABLE_ROWS) < this.m_data.length)){
                    this.m_downBtn.setEnabled(false);
                };
            };
        }
        protected function scrollToCell(_arg1:int):void{
            if (this.m_tween){
                return;
            };
            if ((((_arg1 < 0)) || ((_arg1 > this.m_model.getSize())))){
                return;
            };
            var _local2:int = Math.floor((_arg1 / USABLE_ROWS));
            var _local3:int = (_local2 * USABLE_ROWS);
            if (_local3 == this.m_topCrew){
                return;
            };
            this.setupTween(this.m_topCrew, _local3);
            this.m_topCrew = _local3;
            if (!(this.m_topCrew > 0)){
                this.m_upBtn.setEnabled(false);
            } else {
                this.m_upBtn.setEnabled(true);
            };
            if (!((this.m_topCrew + USABLE_ROWS) < this.m_data.length)){
                this.m_downBtn.setEnabled(false);
            } else {
                this.m_downBtn.setEnabled(true);
            };
        }
        protected function setupTween(_arg1:int, _arg2:int):void{
            var startPos:* = 0;
            var destPos:* = 0;
            var tweenObj:* = null;
            var oldIndex:* = _arg1;
            var newIndex:* = _arg2;
            if (((this.m_tween) && (this.m_tween.data))){
                tweenObj = this.m_tween.data;
            } else {
                startPos = (oldIndex * (ROW_HEIGHT + 1));
                tweenObj = {
                    currentValue:startPos,
                    lastValue:startPos
                };
            };
            destPos = (newIndex * (ROW_HEIGHT + 1));
            var tweenProps:* = {
                currentValue:destPos,
                onStart:function ():void{
                    m_tween.data = tweenObj;
                },
                onUpdate:function ():void{
                    tweenObj.currentValue = Math.ceil(tweenObj.currentValue);
                    m_dataList.scrollVertical((tweenObj.currentValue - tweenObj.lastValue));
                    tweenObj.lastValue = tweenObj.currentValue;
                },
                onComplete:function ():void{
                    m_dataList.scrollVertical((destPos - tweenObj.lastValue));
                    m_tween = null;
                }
            };
            this.m_tween = TweenLite.to(tweenObj, this.TWEEN_TIME, tweenProps);
        }

    }
}//package Display.GateUI 
